<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="####1. 新建项目，导入.so文件将之前编译生成的多个.so文件及inclulde文件夹下的头文件拷贝到/app/libs文件夹下，拷贝后目录结果如下：">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="Android-使用-FFmpeg命令行(多包)">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/FFmpeg/Android-使用-FFmpeg命令行(多包)/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="####1. 新建项目，导入.so文件将之前编译生成的多个.so文件及inclulde文件夹下的头文件拷贝到/app/libs文件夹下，拷贝后目录结果如下：">
<meta property="og:locale" content="default">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-35522113daec48db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-b3d0870e1a173e34.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-15376017c13ecb4e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-e138e953bddbad2b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-16edf1b2700cf6d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-52c212637db93bc8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="http://upload-images.jianshu.io/upload_images/3110861-7e28776ae4d5f387.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-08-06T11:04:48.900Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android-使用-FFmpeg命令行(多包)">
<meta name="twitter:description" content="####1. 新建项目，导入.so文件将之前编译生成的多个.so文件及inclulde文件夹下的头文件拷贝到/app/libs文件夹下，拷贝后目录结果如下：">
<meta name="twitter:image" content="http://upload-images.jianshu.io/upload_images/3110861-35522113daec48db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/FFmpeg/Android-使用-FFmpeg命令行(多包)/"/>





  <title>Android-使用-FFmpeg命令行(多包) | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/FFmpeg/Android-使用-FFmpeg命令行(多包)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android-使用-FFmpeg命令行(多包)</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>####1. 新建项目，导入.so文件<br>将之前编译生成的多个.so文件及inclulde文件夹下的头文件拷贝到/app/libs文件夹下，拷贝后目录结果如下：<br><img src="http://upload-images.jianshu.io/upload_images/3110861-35522113daec48db.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图1.png"></p>
<a id="more"></a>
<p>####2. 配置/app/src/main目录下新建jni文件夹<br><img src="http://upload-images.jianshu.io/upload_images/3110861-b3d0870e1a173e34.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图2.png"></p>
<p>####3. 创建FFmpegCmd.java类<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">package com.mazaiting.ffmpegcmdtest;</span><br><span class="line">/**</span><br><span class="line"> * FFmpeg命令行操作</span><br><span class="line"> * @author mazaiting</span><br><span class="line"> * @date 2018/1/12</span><br><span class="line"> */</span><br><span class="line"></span><br><span class="line">public class FFmpegCmd &#123;</span><br><span class="line"></span><br><span class="line">    static &#123;</span><br><span class="line">        System.loadLibrary(&quot;avcodec-57&quot;);</span><br><span class="line">        System.loadLibrary(&quot;avdevice-57&quot;);</span><br><span class="line">        System.loadLibrary(&quot;avfilter-6&quot;);</span><br><span class="line">        System.loadLibrary(&quot;avformat-57&quot;);</span><br><span class="line">        System.loadLibrary(&quot;avutil-55&quot;);</span><br><span class="line">        System.loadLibrary(&quot;swresample-2&quot;);</span><br><span class="line">        System.loadLibrary(&quot;swscale-4&quot;);</span><br><span class="line">        System.loadLibrary(&quot;FfmpegCmd&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public static int execute(String[] commands) &#123;</span><br><span class="line">        return run(commands);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public native static int run(String[] commands);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####4. 配置/app/build.gradle文件<br>1). 在android节点下的defaultConfig目录下新增<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ndk &#123;</span><br><span class="line">    moduleName &quot;ffmpegcmd&quot;</span><br><span class="line">    abiFilters &quot;armeabi&quot;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>2). 在android节点下新增，如果已有则替换这段<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sourceSets &#123;</span><br><span class="line">    main &#123;</span><br><span class="line">        jniLibs.srcDirs = [&apos;src/main/libs&apos;]</span><br><span class="line">        jni.srcDirs=[]</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####5. 生成jni的头文件<br><a href="https://www.jianshu.com/p/968f50f1a0ee" target="_blank" rel="noopener">javah命令配置</a>, 运行命令完成后，在jni文件夹下生成com_mazaiting_ffmpegcmdtest_FFmpegCmd.h文件<br><img src="http://upload-images.jianshu.io/upload_images/3110861-15376017c13ecb4e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图3.png"></p>
<p>####6.  配置jni目录<br>将ffmpeg源码中的ffmpeg.h, ffmpeg.c, ffmpeg_opt.c, ffmpeg_filter.c，cmdutils.c, cmdutils.h, cmdutils_common_opts.h，config.h 赋值到jni目录下，并在 jni 目录新建文件 Android.mk Application.mk com_mazaiting_ffmpegcmdtest_FFmpegCmd.c。</p>
<p>####7. 修改ffmpeg源码<br>1). 编辑ffmpeg.c，把<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">int main(int argc, char **argv)</span><br></pre></td></tr></table></figure></p>
<p>改名为<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">int run(int argc, char **argv)</span><br></pre></td></tr></table></figure></p>
<p>编辑ffmpeg.h, 在文件末尾(在#endif前面)添加函数申明:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">int run(int argc, char **argv)</span><br></pre></td></tr></table></figure></p>
<p>2). 编辑cmdutils.c中的exit_program函数，删掉函数中原来的内容, 添加 return ret；并修改函数的返回类型为int。<br>长这样：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">int exit_program(int ret)</span><br><span class="line">&#123;</span><br><span class="line">    return ret;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>编辑cmdutils.h中exit_program的申明，把返回类型修改为int。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">int exit_program(int ret);</span><br></pre></td></tr></table></figure></p>
<p>####8. 其他文件<br>1). com_mazaiting_ffmpegcmdtest_FFmpegCmd.c<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">#include &quot;com_mazaiting_ffmpegcmdtest_FFmpegCmd.h&quot;</span><br><span class="line">#include &quot;ffmpeg.h&quot;</span><br><span class="line">#include &lt;android/log.h&gt;</span><br><span class="line"></span><br><span class="line">#define LOGI(FORMAT, ...) __android_log_print(ANDROID_LOG_INFO,&quot;ffmpeg&quot;,FORMAT,##__VA_ARGS__);</span><br><span class="line">#define LOGE(FORMAT, ...) __android_log_print(ANDROID_LOG_ERROR,&quot;ffmpeg&quot;,FORMAT,##__VA_ARGS__);</span><br><span class="line"></span><br><span class="line">JNIEXPORT jint JNICALL Java_com_mazaiting_ffmpegcmdtest_FFmpegCmd_run</span><br><span class="line">  (JNIEnv *env, jclass cls, jobjectArray commands) &#123;</span><br><span class="line"></span><br><span class="line">      int argc = (*env)-&gt;GetArrayLength(env, commands);</span><br><span class="line">      char *argv[argc];</span><br><span class="line"></span><br><span class="line">      LOGE(&quot;Kit argc %d\n&quot;, argc);</span><br><span class="line">      int i;</span><br><span class="line">      for (i = 0; i &lt; argc; i++) &#123;</span><br><span class="line">          jstring js = (jstring)(*env)-&gt;GetObjectArrayElement(env, commands, i);</span><br><span class="line">          argv[i] = (char *) (*env)-&gt;GetStringUTFChars(env, js, 0);</span><br><span class="line">          LOGE(&quot;Kit argv %s\n&quot;, argv[i]);</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      return run(argc, argv);</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></p>
<p>2). Android.mk<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">LOCAL_PATH := $(call my-dir)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line"># 打印当前路径</span><br><span class="line">$(warning $(LOCAL_PATH))</span><br><span class="line"># .so文件名称，去除前缀lib和-后的内容</span><br><span class="line">LOCAL_MODULE := avcodec</span><br><span class="line"># .so文件</span><br><span class="line">LOCAL_SRC_FILES := libavcodec-57.so</span><br><span class="line"># 已编译好的库使用PREBUILT_SHARED_LIBRARY</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := avdevice</span><br><span class="line">LOCAL_SRC_FILES := libavdevice-57.so</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := avfilter</span><br><span class="line">LOCAL_SRC_FILES := libavfilter-6.so</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := avformat</span><br><span class="line">LOCAL_SRC_FILES := libavformat-57.so</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := avutil</span><br><span class="line">LOCAL_SRC_FILES := libavutil-55.so</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := swresample</span><br><span class="line">LOCAL_SRC_FILES := libswresample-2.so</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># FFmpeg library</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := swscale</span><br><span class="line">LOCAL_SRC_FILES := libswscale-4.so</span><br><span class="line">include $(PREBUILT_SHARED_LIBRARY)</span><br><span class="line"></span><br><span class="line"># Program</span><br><span class="line"># module名称</span><br><span class="line">include $(CLEAR_VARS)</span><br><span class="line">LOCAL_MODULE := FfmpegCmd</span><br><span class="line"># module中的源文件</span><br><span class="line">LOCAL_SRC_FILES := com_mazaiting_ffmpegcmdtest_FFmpegCmd.c ffmpeg.c ffmpeg_opt.c cmdutils.c ffmpeg_filter.c</span><br><span class="line"># ffmpeg源码路径</span><br><span class="line">LOCAL_C_INCLUDES += C:/Users/Administrator/Desktop/ffmpeg-3.3.6</span><br><span class="line">LOCAL_LDLIBS := -llog -lz</span><br><span class="line"># 链接的动态库文件</span><br><span class="line">LOCAL_SHARED_LIBRARIES := avcodec avdevice avfilter avformat avutil swresample swscale</span><br><span class="line"># 编译生成的库使用BUILD_SHARED_LIBRARY</span><br><span class="line">include $(BUILD_SHARED_LIBRARY)</span><br></pre></td></tr></table></figure></p>
<p>3). Application.mk<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">APP_MODULES := FfmpegCmd</span><br><span class="line">APP_ABI := armeabi</span><br><span class="line">APP_PLATFORM := android-14</span><br><span class="line"># 去除原子性编译</span><br><span class="line">APP_LDFLAGS := -latomic</span><br></pre></td></tr></table></figure></p>
<p>####9. 编译FfmpegCmd.so文件<br>编译之前先将/app/libs文件夹内的ffmpeg中拷贝的.so文件拷贝到jni文件夹一份，此时jni文件夹内的所有文件如图4，使用ndk-build命令编译(图5)。<br><img src="http://upload-images.jianshu.io/upload_images/3110861-e138e953bddbad2b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图4.png"></p>
<p><img src="http://upload-images.jianshu.io/upload_images/3110861-16edf1b2700cf6d6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图5.png"></p>
<p>####10. 编译成功<br>编译成功后在main目录下生成libs和obj文件夹，将/libs/armeabi/下的libFfmpegcmd.so或者/obj/local/armeabi/objs/下的libFfmpegcmd.so文件复制到/app/libs/armeabi/目录下，此时在java文件中即可成功使用ffmpeg。<br><img src="http://upload-images.jianshu.io/upload_images/3110861-52c212637db93bc8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图6.png"></p>
<p>####11. 使用<br>1). 在AndroidManifest.xml添加权限<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;</span><br><span class="line">&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;</span><br></pre></td></tr></table></figure></p>
<p>2). activity_main.xml<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</span><br><span class="line">&lt;RelativeLayout</span><br><span class="line">    xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;</span><br><span class="line">    xmlns:tools=&quot;http://schemas.android.com/tools&quot;</span><br><span class="line">    android:id=&quot;@+id/activity_main&quot;</span><br><span class="line">    android:layout_width=&quot;match_parent&quot;</span><br><span class="line">    android:layout_height=&quot;match_parent&quot;</span><br><span class="line">    tools:context=&quot;com.mazaiting.ffmpegcmdtest.MainActivity&quot;&gt;</span><br><span class="line"></span><br><span class="line">    &lt;Button</span><br><span class="line">        android:onClick=&quot;start&quot;</span><br><span class="line">        android:layout_width=&quot;wrap_content&quot;</span><br><span class="line">        android:layout_height=&quot;wrap_content&quot;</span><br><span class="line">        android:text=&quot;合成&quot;/&gt;</span><br><span class="line">&lt;/RelativeLayout&gt;</span><br></pre></td></tr></table></figure></p>
<p>3). MainActivity.java<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">public class MainActivity extends AppCompatActivity &#123;</span><br><span class="line">    private static final String TAG = &quot;MainActivity&quot;;</span><br><span class="line">    private boolean isRun = false;</span><br><span class="line">    /**视频源路径*/</span><br><span class="line">    private String videoUrl = &quot;/storage/emulated/0/input.mp4&quot;;</span><br><span class="line">    /**图片路径*/</span><br><span class="line">    private String imageUrl = &quot;/storage/emulated/0/image.png&quot;;</span><br><span class="line">    /**视频输出路径*/</span><br><span class="line">    private String outputUrl = &quot;/storage/emulated/0/output.mp4&quot;;</span><br><span class="line">    @Override</span><br><span class="line">    protected void onCreate(Bundle savedInstanceState) &#123;</span><br><span class="line">        super.onCreate(savedInstanceState);</span><br><span class="line">        setContentView(R.layout.activity_main);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    public void start(View view)&#123;</span><br><span class="line">        if (!isRun) &#123;</span><br><span class="line">            new Thread(mRunnable).start();</span><br><span class="line">            isRun = true;</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            Toast.makeText(this, &quot;正在运行&quot;, Toast.LENGTH_SHORT).show();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    /**</span><br><span class="line">     * 添加水印任务</span><br><span class="line">     */</span><br><span class="line">    Runnable mRunnable = new Runnable() &#123;</span><br><span class="line">        @Override</span><br><span class="line">        public void run() &#123;</span><br><span class="line">            String[] commands = new String[10];</span><br><span class="line">            commands[0] = &quot;ffmpeg&quot;;</span><br><span class="line">            commands[1] = &quot;-i&quot;;</span><br><span class="line">            commands[2] = videoUrl;</span><br><span class="line">            commands[3] = &quot;-i&quot;;</span><br><span class="line">            commands[4] = imageUrl;</span><br><span class="line">            commands[5] = &quot;-filter_complex&quot;;</span><br><span class="line">            commands[6] = &quot;overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2&quot;;</span><br><span class="line">            commands[7] = &quot;-codec:a&quot;;</span><br><span class="line">            commands[8] = &quot;copy&quot;;</span><br><span class="line">            commands[9] = outputUrl;</span><br><span class="line"></span><br><span class="line">            Log.e(TAG, &quot;run: 开始执行&quot;);</span><br><span class="line">            FFmpegCmd.execute(commands);</span><br><span class="line">            Log.e(TAG, &quot;run: 执行结束&quot;);</span><br><span class="line">            isRun = false;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>####12. 运行结果<br><img src="http://upload-images.jianshu.io/upload_images/3110861-7e28776ae4d5f387.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图7.png"></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/FFmpeg/Android-Studio使用FFmpeg/" rel="next" title="Android-Studio使用FFmpeg">
                <i class="fa fa-chevron-left"></i> Android-Studio使用FFmpeg
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/FFmpeg/FFmpeg-命令/" rel="prev" title="FFmpeg-命令">
                FFmpeg-命令 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
